/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Food.java]
 * Creation Date        [21-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_03_game.greedysnake_V2.model;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Random;

import pkg_03_game.greedysnake_V2.constants.Constants;

/**
 * 食物, 有x , y 坐标 和 颜色等属性<br/>
 * 可以用setColor() 改变食物的颜色<br/>
 * 也可以通过覆盖drawFood方法改变食物的显示方式<br/>
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 */
public class Food extends Point {

	private static final long serialVersionUID = 1L;

	/* 食物的颜色 */
	private Color color = new Color(0xcc0033);

	private final Random random = new Random();

	/**
	 * 默认的构造器, 产生(0,0)的坐标
	 */
	public Food() {
		super();
	}

	public Point getNew() {
		Point p = new Point();
		p.x = random.nextInt(Constants.WIDTH);
		p.y = random.nextInt(Constants.HEIGHT);
		return p;
	}

	/**
	 * 初始化坐标和指定坐标相同的构造器
	 */
	public Food(Point p) {
		super(p);
	}

	/**
	 * 蛇是否吃到了食物
	 */
	public boolean isSnakeEatFood(Snake snake) {
		return equals(snake.getHead());
	}

	/**
	 * 绘制食物, 将调用 drawFood方法
	 */
	public void drawMe(Graphics g) {
		g.setColor(color);
		drawFood(g, x * Constants.CELL_WIDTH, y * Constants.CELL_HEIGHT,
				Constants.CELL_WIDTH, Constants.CELL_HEIGHT);
	}

	/**
	 * 画食物, 可以覆盖这个方法改变食物的显示
	 */
	public void drawFood(Graphics g, int x, int y, int width, int height) {
		g.fill3DRect(x, y, width, height, true);
	}

	/**
	 * 得到食物的颜色
	 */
	public Color getColor() {
		return color;
	}

	/**
	 * 设置食物的颜色
	 */
	public void setColor(Color color) {
		this.color = color;
	}

}
